import { isUrl } from '../utils/utils';

const menuData = [
    {
        name: '地块信息导入',
        icon: 'codepen-circle',
        path: 'massif',
        authority: ['admin'],
        children: [
            {
                name: '整改报备',
                path: 'rectify',
                authority: ['admin'],
                children: [
                    {
                        name: '整改报备项目',
                        path: 'project',
                        authority: ['admin'],
                    },
                    {
                        name: '拆旧区',
                        path: 'squatter',
                        authority: ['admin'],
                    },
                    {
                        name: '农村建新区',
                        path: 'countryside',
                        authority: ['admin'],
                    },
                    {
                        name: '城镇建新区',
                        path: 'town',
                        authority: ['admin'],
                    },
                ],
            },
        ],
    },
    /* {
        name: '异常页',
        icon: 'warning',
        path: 'exception',
        children: [
            {
                name: '403',
                path: '403',
            },
            {
                name: '404',
                path: '404',
            },
            {
                name: '500',
                path: '500',
            },
            {
                name: '触发异常',
                path: 'trigger',
                hideInMenu: true,
            },
        ],
    }, */
    {
        name: '账户',
        icon: 'user',
        path: 'user',
        authority: 'guest',
        children: [
            {
                name: '登录',
                path: 'login',
            },
            {
                name: '注册',
                path: 'register',
            },
            {
                name: '注册结果',
                path: 'register-result',
            },
        ],
    },
];

function formatter(data, parentPath = '/', parentAuthority) {
    return data.map((item) => {
        let { path } = item;
        if (!isUrl(path)) {
            path = parentPath + item.path;
        }
        const result = {
            ...item,
            path,
            authority: item.authority || parentAuthority,
        };
        if (item.children) {
            result.children = formatter(
                item.children,
                `${parentPath}${item.path}/`,
                item.authority
            );
        }
        return result;
    });
}

export const getMenuData = () => formatter(menuData);
